package com.hc.acoustics.ui.activity

import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.hc.acoustics.R
import com.hc.acoustics.base.BaseActivity
import com.hc.acoustics.bean.contact.FormulaType
import com.hc.acoustics.bean.contact.MainType
import com.yc.yclibrary.base.YcAppCompatActivity
import com.yc.yclibx.adapter.YcAdapterHelper
import com.yc.yclibx.adapter.YcRecyclerViewAdapter
import kotlinx.android.synthetic.main.type_formula_activity.*

/**
 *
 */
class FormulaTypeActivity : BaseActivity() {
    private lateinit var mAdapter: YcRecyclerViewAdapter<String>

    @MainType.State
    private var mMainType: Int = MainType.State.Main_1

    companion object {
        private const val KEY_MAIN_TYPE = "KEY_MAIN_TYPE"
        @JvmStatic
        fun newInstance(activity: YcAppCompatActivity, @MainType.State mainType: Int) {
            val intent = Intent(activity, FormulaTypeActivity::class.java)
            intent.putExtra(KEY_MAIN_TYPE, mainType)
            activity.startActivity(intent)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.type_formula_activity
    }

    override fun initView(savedInstanceState: Bundle?) {
        mMainType = intent.getIntExtra(KEY_MAIN_TYPE, MainType.State.Main_1)
        setActionBar(MainType.getTitleName(mMainType))
        mAdapter = object : YcRecyclerViewAdapter<String>(this, R.layout.type_formula_item) {
            override fun onUpdate(helper: YcAdapterHelper, item: String, position: Int) {
                helper.setText(R.id.typeFormulaItemTv, item)
            }
        }
        mAdapter.setItemClickListener { viewHolder, view, position ->
            FormulaType.toFormulaActivity(activity, mMainType, position)
        }

        mAdapter.addAll(FormulaType.getData(mMainType))
        typeFormulaRv.adapter = mAdapter
        typeFormulaRv.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
    }
}
